package com.tour.manage;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.tour.model.TicketOrder;

public class TicketOrderManager {

	private HibernateTemplate ht = null;
	private SessionFactory sessionFactory = null;
	
	private HibernateTemplate getHibernateTemplate() {
		if(ht == null) {
			ht = new HibernateTemplate(sessionFactory);
		}
		
		return ht;
	}
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public List<TicketOrder> listMemberTicketOrders(Integer memberId) {
		return (List<TicketOrder>) getHibernateTemplate()
			.find("from TicketOrder o where o.memberId = ?", memberId);
	}
	
	public TicketOrder get(Integer id) {
		return (TicketOrder) getHibernateTemplate().get(TicketOrder.class, id);
	}
	
	public Integer addTicketOrder(TicketOrder order) {
		return (Integer) getHibernateTemplate().save(order);
	}
	
	public void modifyTicketOrder(TicketOrder ticketOrder) {
		getHibernateTemplate().update(ticketOrder);
	}
	
	public void deleteTicketOrder(TicketOrder ticketOrder) {
		getHibernateTemplate().delete(ticketOrder);
	}
}
